<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

/**
 * SPA 认证功能：用户登录
 * Class LoginController
 * @package App\Http\Controllers\Api
 */
class LoginController extends \App\Http\Controllers\Controller
{
    public function authenticate(Request $request)
    {
        $credentials = $request->only('email', 'password');
//        var_dump($credentials);exit;
        /*
            array(2) {
            ["email"]=>
            string(11) "amen@qq.com"
            ["password"]=>
            string(60) "$2y$10$eCkKEWcKOMith8OPaYBRhu9m6KhE53hcCZPG3/ySGLHqEeukDwOF."
            }
         */
        if (Auth::attempt($credentials)) {
            // 通过认证..
            return [
                'code' => 20000
            ];
        } else {
            return [
                'code' => 40000
            ];
        }
    }
}
